package com.inspur.sc.springboot.service.impl;

import com.inspur.sc.springboot.dao.SysRoleUserDao;
import com.inspur.sc.springboot.entity.SysRoleUser;
import com.inspur.sc.springboot.service.SysRoleUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
public class SysRoleUserServiceImpl implements SysRoleUserService {

    @Autowired
    private SysRoleUserDao roleUserDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(SysRoleUser roleUser) {
        try{
            roleUserDao.save(roleUser);
            return true;
        }catch (Exception e){
            log.error(e.getMessage());
            return false;
        }
    }

    @Override
    public SysRoleUser findById(Integer id) {
        return roleUserDao.findById(id).get();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(Integer id) {
        try{
            roleUserDao.deleteById(id);
            return true;
        }catch (Exception e){
            log.error(e.getMessage());
            return false;
        }
    }

    @Override
    public List<SysRoleUser> findBySysUserId(Integer userId) {
        return roleUserDao.findBySysUserId(userId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBySysUserId(Integer userId) {
        try {
            roleUserDao.deleteBySysUserId(userId);
            return true;
        }catch (Exception e){
            log.error(e.getMessage());
            return false;
        }

    }
}
